require(['../config'], () => {
    require(['template', 'header', 'footer'], (template) => {
        class list2 {
            constructor() {
                this.getinfo();
                this.getinfo2();
            }

            getinfo() {
                $.get('http://rap2api.taobao.org/app/mock/241085/list', resp => {
                    var html = template('getin2', { list: resp })
                    $('#reduceList').html(html)
                    this.priceScreen()
                    this.nowTime();

                })
            }
            getinfo2() {
                    $.get('http://rap2api.taobao.org/app/mock/241085/list2', resp => {
                        if (resp.code === 200) {
                            var html = template('getin3', { list: resp.body })
                            $('#reduceList2').html(html)
                        }
                    })
                }
                //价格排序
            priceScreen() {
                $('#jg').on('click', () => {
                    $('#reduceList2 li').remove()
                    $.get('http://rap2api.taobao.org/app/mock/241085/list2', resp => {
                        if (resp.code === 200) {
                            const list = resp.body
                            list.sort(function(a, b) {
                                return b.shopPrice - a.shopPrice
                            })
                            var html = template('getin3', { list: resp.body })
                            $('#reduceList2').html(html)
                        }
                    })
                })
            }

            nowTime() {
                setInterval(function() {
                    var myDate = new Date;
                    var h = myDate.getHours(); //获取当前小时数(0-23)
                    var m = myDate.getMinutes(); //获取当前分钟数(0-59)
                    var s = myDate.getSeconds(); //获取当前秒
                    h = check(h);
                    m = check(m);
                    s = check(s);
                    $("#by").html(h + " : " + m + " : " + s);
                }, 1000)

                function check(i) {
                    //方法一，用三元运算符
                    var num;
                    i < 10 ? num = "0" + i : num = i;
                    return num;

                }
            }
        }
        new list2()
    })
})